package cn.edu.scau.sec.caixiaoqing.singleton;

/**
 * 实现饿汉式单例模式（在未被调用前创建实例，防止在多线程情况下出现错误）
 */
public class Chairman {
    private Chairman(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    private String name;
    private static Chairman chairman = new Chairman("毛泽东");

    public static Chairman getInstance(){
        return chairman;
    }

    public static void compChairman(Chairman chairman1,Chairman chairman2){
        if (chairman1==chairman2) System.out.println("这两次创建的主席是同一个对象");
        else System.out.println("这两次创建的主席是同一个对象");
    }

    public static void printChairman(Chairman chairman){
        System.out.println("您实际得到的主席是："+ chairman.getName()+";");
    }
}
